package com.hyt.it.ogt.ykcj.common.core.page;

import com.hyt.it.ogt.ykcj.common.utils.ServletUtils;

/**
 * 表格数据处理
 * 
 * @author admin
 */
public class TableSupport
{
    /**
     * 当前记录起始索引
     */
    public static final String PAGE_NUM = "pageNum";
    
    /**
     * 当前记录起始索引
     */
    public static final String CURRENT = "current";

    /**
     * 每页显示记录数
     */
    public static final String PAGE_SIZE = "pageSize";
    
    /**
     * 每页显示记录数
     */
    public static final String SIZE = "size";

    /**
     * 排序列
     */
    public static final String ORDER_BY_COLUMN = "orderByColumn";

    /**
     * 排序的方向 "desc" 或者 "asc".
     */
    public static final String IS_ASC = "isAsc";
    /**
     * 排序的方向 "desc" 或者 "asc".
     */
    public static final String ORDER_BY = "orderBy";

	/**
	 * 封装分页对象
	 */
	public static PageDomain getPageDomain() {
		PageDomain pageDomain = new PageDomain();
		Integer pageNum = ServletUtils.getParameterToInt(PAGE_NUM);
		if (null == pageNum)
			pageNum = ServletUtils.getParameterToInt(CURRENT);
		pageDomain.setPageNum(pageNum);
		Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE);
		if (null == pageSize)
			pageSize = ServletUtils.getParameterToInt(SIZE);
		pageDomain.setPageSize(pageSize);
		pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN));
		pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC));
		return pageDomain;
	}

	public static PageDomain buildPageRequest() {
		return getPageDomain();
	}
}
